// [561]数组拆分
struct Solution;

//leetcode submit region begin(Prohibit modification and deletion)
impl Solution {
    pub fn array_pair_sum(nums: Vec<i32>) -> i32 {
        let mut nums = nums;
        nums.sort();
        let mut ans = 0;
        for (i, &num) in nums.iter().enumerate() {
            if i % 2 == 0 {
                ans += num;
            }
        }
        ans
    }
}
//leetcode submit region end(Prohibit modification and deletion)


#[test]
fn main() {
    let nums = vec![1,4,3,2];
    assert_eq!(Solution::array_pair_sum(nums), 4);
    let nums = vec![6,2,6,5,1,2];
    assert_eq!(Solution::array_pair_sum(nums), 9);
}